from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 关注房源用例：case_003---正向用例

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://bj.5i5j.com/')

# 隐式等待
driver.implicitly_wait(5)

sleep(3)
# 点击登录
driver.find_element(By.ID, 'home-login-btn').click()
sleep(2)
# 点击密码登录
driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div[3]/div[2]').click()
sleep(2)
# 显示等待***输入账号
sjh = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="phone1"]'))
)
# 输入账号
sjh.send_keys('15985645480')
sleep(2)
# 输入密码
driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div[4]/div[3]/input').send_keys('gW09092434')
sleep(2)
# 点击立即登录
driver.find_element(By.ID, 'login-submit').click()
sleep(3)
# 输入房源信息查询
driver.find_element(By.ID, 'search-inp').send_keys('朝阳区')
sleep(2)
# 点击开始找房
driver.find_element(By.XPATH, '//*[@id="search-wrap"]/div[2]').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(3)
# 选择位置区域：朝阳
driver.find_element(By.XPATH, '/html/body/div[6]/div/div[2]/ul/li[1]/div[3]/div[1]/ul/a[2]/li').click()
sleep(2)
# 点击房源图片
driver.find_element(By.XPATH, '/html/body/div[7]/div[1]/div[2]/ul/li[1]/div[1]/a/img').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(3)
# 点击关注房源（关注房源）
fy = driver.find_element(By.XPATH, '/html/body/div[6]/div[1]/div[2]/div/a[1]/span')
fy.click()
# 获取元素文本
print(f"元素文本：{fy.text}")
# 获取元素尺寸
print(f"元素尺寸-宽度：{fy.size['width']}, 高度：{fy.size['height']}")
# 获取元素坐标
print(f"元素坐标-x：{fy.location['x']}, y:{fy.location['y']}")
sleep(2)
# 再次点击关注房源（取消关注房源）
driver.find_element(By.XPATH, '/html/body/div[6]/div[1]/div[2]/div/a[1]/span').click()

sleep(10)






